<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="../js/axios.min.js" type="text/javascript"></script>
    <script src="../js/vue.js" type="text/javascript"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <title>我的预约</title>
</head>
<body>
<div id="app">
    <el-container>
        <el-main>
            <!--条件查询-->
            <el-form :inline="true" :model="condition" class="demo-form-inline">
                <el-form-item label="查询">
                    <el-input v-model="condition" placeholder="关键字"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="query">查询</el-button>
                </el-form-item>
            </el-form>

            <!--展示我的私教-->
            <el-table :data="book" border>
                <el-table-column prop="bookId" label="ID" v-if="false">
                </el-table-column>
                <el-table-column prop="no" label="预约号">
                </el-table-column>
                <el-table-column prop="userName" label="预约人">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                </el-table-column>
                <el-table-column prop="lessonName" label="课程">
                </el-table-column>
                <el-table-column prop="lessonTime" label="上课时间">
                </el-table-column>
                <el-table-column prop="state" label="状态">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button v-show="scope.row.state=='待处理'" @click="access(scope.row)" type="text" size="small">接
                            受
                        </el-button>
                        <el-button v-show="scope.row.state=='待处理'" @click="showRefuse(scope.row)" type="text"
                                   size="small">拒 绝
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageInfo.currentPage"
                        :page-sizes="[3, 4]"
                        :page-size="100"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageInfo.total">
                </el-pagination>
            </div>
        </el-main>
    </el-container>
    <el-dialog
            title="拒绝理由"
            :visible.sync="dialogVisible"
            width="30%">
        <el-item label="原因">
            <el-input v-model="message" placeholder="拒绝理由"></el-input>
        </el-item>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="refuse">确 定</el-button>
        </span>
    </el-dialog>
</div>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                pageInfo: {
                    currentPage: 1,// 当前页
                    size: 3,// 每页多少条
                    total: 1// 总条目数
                },
                book: {
                    bookId: "",
                    no: "",
                    userName: "",
                    createTime: "",
                    lessonName: "",
                    lessonTime: "",
                    state: "",

                },
                condition: "",
                dialogVisible: false,
                message: "",
                id: ""
            }
        },
        methods: {
            showRefuse(row) {
                    this.dialogVisible = true;
                    this.id = row.bookId;
            },
            // 分页 - 更改每页条数
            handleSizeChange(val) {
                this.pageInfo.size = val
                this.query();
            },
            // 分页 - 更改当前页
            handleCurrentChange(val) {
                this.pageInfo.currentPage = val
                this.query();
            },
            access(row) {
                this.id = row.bookId;
                console.log(this.id);
                axios.post("/book/access?bookId=" + this.id).then(resp => {
                    if (resp.data.code == 200 && resp.status == 200) {
                        alert("接受成功")
                        this.query()
                    }
                })
            },
            refuse(row) {
                    axios.post("/book/refuse?bookId=" + this.id + "&message=" + this.message).then(resp => {
                        if (resp.data.code == 200 && resp.status == 200) {
                            alert("已拒绝")
                            this.dialogVisible = false;
                            this.query()
                        }
                    })

            },
            query() {
                axios.get("/book/my?condition=" + this.condition + "&current=" + this.pageInfo.currentPage + "&size=" + this.pageInfo.size).then(resp => {
                    if (resp.data.code == 200 && resp.status == 200) {
                        this.book = resp.data.data.records;
                        this.pageInfo.total = resp.data.data.total
                    }
                })
            }
        },
        created() {
            this.query()
        }
    })
</script>
</body>
</html>